package com.hnevc.androidui10;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;


public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        InputStream in=this.getResources().openRawResource(R.raw.data);

        try {


            byte[]bytes=new byte[in.available()];
            in.read(bytes);
            String temp=new String(bytes);
            try {
                JSONObject jsonObject=new JSONObject(temp);
                String author=jsonObject.getString("author");
                JSONArray array=jsonObject.getJSONArray("publisher");
               String publisher1=(String) array.get(0);
                Toast.makeText(this, publisher1, Toast.LENGTH_SHORT).show();
                Toast.makeText(this, author, Toast.LENGTH_SHORT).show();

            } catch (JSONException e) {
                e.printStackTrace();
            }


        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
